using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Managers : MonoBehaviour, IManager
{
    private List<IManager> managers;

    private void Awake()
    {
        Init();
    }

    public void Init()
    {
        SetOrientation();
        DontDestroyOnLoad(this.gameObject);
        managers = new List<IManager>()
        {
            CreateManager<Loader>(),
            CreateManager<AudioMgr>(),
            CreateManager<UIMgr>(),
            CreateManager<Networker>(),
            CreateManager<DataMgr>()
        };
        foreach (var manager in managers)
        {
            manager.Init();
        }
    }

    public void UnInit()
    {
        foreach (var manager in managers)
        {
            manager.UnInit();
        }
    }

    public void OnApplicationQuit()
    {
        UnInit();
    }

    private void SetOrientation()
    {
#if UNITY_ANDROID
        Screen.autorotateToLandscapeLeft = true;
        Screen.autorotateToLandscapeRight = true;
        Screen.autorotateToPortrait = false;
        Screen.autorotateToPortraitUpsideDown = false;
#endif
    }

    private T CreateManager<T>() where T:MonoSingleton<T>
    {
        GameObject obj = new GameObject(typeof(T).Name);
        obj.transform.SetParent(transform);
        return obj.RequireComponent<T>();
    }
}
